package com.cabrida.livestar.util;

import com.cabrida.livestar.BaseApplication;
import com.loopj.android.http.AsyncHttpClient;

/**
 * HTTP 工具类 用于项目中的简单请求
 */
public class HttpUtils extends AsyncHttpClient {
	private static HttpUtils client; // 实例话对象

	public static HttpUtils getClient() {
		if (null == client) {
			client = new HttpUtils();
			String sessionId = LoginUtils.getSession(BaseApplication.getApplication());
			String agent = System.getProperty("http.agent");
			client.setUserAgent(agent);
			client.setTimeout(20000); // 设置链接超时，如果不设置，默认为10s
			client.addHeader("sessionId", sessionId);
			L.e("UserAgent", agent, true);
			L.e("sessionId", sessionId, true);
		}
		return client;
	}

	public static void setSession(String session) {
		getClient().addHeader("sessionId", session);
	}
}
